﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using edowork.com.SQL2005;

namespace WebInvoicingsys.basecontrol.purchase
{
    public partial class uc_from_purchaseplan : System.Web.UI.UserControl
    {
        private void bind()
        {
            Execute exec = new Execute(Session["connectionString"].ToString());

            string sql = String.Format("select pspid, years, month, remark from purchaseplan where m_stu='0' and userid='{0}' order by pspid", Session["userid"].ToString());
            string error_msg = "";

            DataSet ds = exec.ExecSQLQueryDataSet(sql, ref error_msg);

            ddlist.Items.Add(new ListItem("请选择采购计划单", ""));

            if (ds == null)
            {
                return;
            }

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ddlist.Items.Add(new ListItem(String.Format("{0}年{1}月({2})", dr["years"].ToString(), dr["month"].ToString(), dr["remark"].ToString())
                                              , dr["pspid"].ToString()));
            }

            ddlist.SelectedIndex = 0;
        }

        public string getValue()
        {
            return ddlist.SelectedValue.ToString();
        }

        public string getText()
        {
            return ddlist.Text;
        }

        public void Reset()
        {
            ddlist.SelectedIndex = 0;
        }

        public void SetByValue(string value)
        {
            try
            {
                ddlist.ClearSelection();
                ddlist.Items.FindByValue(value).Selected = true;
            }
            catch
            {
                ddlist.ClearSelection();
                ddlist.SelectedIndex = 0;
            }
        }

        public void SetByText(string text)
        {
            try
            {
                ddlist.ClearSelection();
                ddlist.Items.FindByText(text).Selected = true;
            }
            catch
            {
                ddlist.ClearSelection();
                ddlist.SelectedIndex = 0;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
    }
}